package com.tanhua.server.interceptor;

import com.tanhua.domain.db.User;

public class UserHolder {
    private static ThreadLocal<User> tl = new ThreadLocal<>();
    private static ThreadLocal<String> tokenTl = new ThreadLocal<>();

    /**
     * 把User对象绑定到当前线程
     * @param user user对象
     */
    public static void setUser(User user){
        tl.set(user);
    }

    /**
     * 从当前线程上获取绑定的User对象
     */
    public static User getUser(){
        return tl.get();
    }

    /**
     * 从当前线程上清理掉绑定的User对象
     */
    public static void removeUser() {
        tl.remove();
    }
    public  static void setToken(String token) {
        tokenTl.set(token);
    }

    public static String getToken(){
        return tokenTl.get();
    }

    public static void removeToken(){
        tokenTl.remove();
    }
}